#ifndef Z_EXT_H
#define Z_EXT_H
#include <iostream>
#include <sstream>
#include <zlib.h>
using namespace std;
#define ZEXT_CHUNK 16384
class ZExt
{
public:
	stringstream buf;
private:
	/*
	* the target out stream,default is ZExt.buf
	*/
	basic_ostream<char> *out;
	z_stream strm;
	unsigned char ibuf[ZEXT_CHUNK];
	unsigned char obuf[ZEXT_CHUNK];
public:
	ZExt(void);
	~ZExt(void);
	void clearBuf();
	string bufStr();
	size_t readBuf(unsigned char* _b,size_t blen);
	void ostream(basic_ostream<char>* _out);
	//
	void initDeflate(int lev=Z_DEFAULT_COMPRESSION);
	int deflat(string data,int finish=Z_FINISH);
	int deflat(unsigned char* data,size_t len,int finish=Z_FINISH);
	int deflat(basic_istream<char>* _in);
	//
	void initInflate();
	int inflat(unsigned char* data,size_t len,int finish=Z_FINISH);
	int inflat(basic_istream<char>* _in);
};

#endif